//package org.wlgzs.shop.utils.file;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Service;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.multipart.MultipartHttpServletRequest;
//import org.springframework.web.multipart.commons.CommonsMultipartResolver;
//import org.springframework.web.servlet.ModelAndView;
//import org.wlgzs.shop.controller.CouponsController;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.File;
//import java.io.IOException;
//import java.util.Iterator;
//import java.util.UUID;
//
///**
// * @Author: Ben
// * @Date: 2019/5/25 15:29
// * @Project org.wlgzs.shop
// */
//@Service
//public class FileUtils {
//    private static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
//
//    public static ModelAndView oneFileUploadService(HttpServletRequest request, HttpServletResponse response, CommonsMultipartResolver commonsMultipartResolver,ModelAndView modelAndView) throws IOException {
//        if (commonsMultipartResolver.isMultipart(request)) {
//            MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) (request);
//            Iterator<String> files = multipartHttpServletRequest.getFileNames();
//            while (files.hasNext()) {
//                MultipartFile multipartFile = multipartHttpServletRequest.getFile(files.next());
//                if (multipartFile != null) {
//                    String fileName = UUID.randomUUID()
//                            + multipartFile.getOriginalFilename();
//                    String path = "d:/upload/" + fileName;
//                    File localFile = new File(path);
//                    multipartFile.transferTo(localFile);
//                    modelAndView.addObject("fileUrl", path);
////                    request.setAttribute("fileUrl", path);
//                    return modelAndView;
//                }else {
//                    logger.error("您要上传的文件为空");
//                    modelAndView.addObject("error","您要上传的文件为空");
//                    return modelAndView;
//                }
//            }
//        }else {
//            logger.error("您提交的表单请求不是文件请求");
//            modelAndView.addObject("error","您提交的表单请求不是文件请求");
//            return modelAndView;
//        }
//        return modelAndView;
//    }
//}
